var {
    verifyToken
} = require('../utils/jwt')

function checkAuth(req, res, next) {
    let token = req.headers.authorization
    let newToken = token && token.replace("Bearer ", "");
    if (!newToken || verifyToken(newToken) === "Token Invalid") {
        res.send({
            code: 50000,
            msg: '未登录'
        })
    } else {
        next()
    }
}

module.exports = checkAuth